package com.example.project.controller;

import com.example.project.base.BaseApi;
import com.example.project.base.ResultBean;
import com.example.project.config.shiro.ShiroCacheObj;
import com.example.project.entity.TAdmin;
import com.example.project.service.TModuleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/tmodule")
@Api(value = "TModuleController",tags = "功能模块相关")
public class TModuleController extends BaseApi {
    @Autowired
    TModuleService tModuleService;

    @RequestMapping(value = "/getAllModule",method = RequestMethod.POST)
    @ApiOperation("获取所有管理模块")
    public ResultBean getAllModule(Integer pageNo,Integer pageSize){
        try{
            PageHelper.startPage(pageNo==null?0:pageNo,pageSize==null?0:pageSize);
            PageInfo<TAdmin> list=new PageInfo(tModuleService.queryAll());
            return ok("成功",list);
        }catch (Exception e){
            e.printStackTrace();
            return fail("查询失败");
        }
    }

    @RequestMapping(value = "/getAllModuleNo",method = RequestMethod.POST)
    @ApiOperation("根据缓存信息获取当前功能模块")
    public ResultBean getAllModuleNo(){
        try{
            ShiroCacheObj shiroCacheObj=currAdminInfo();
            List<String> moduleSet= tModuleService.getAllModuleNoByUserId(shiroCacheObj.getUserId());
            return ok("成功",moduleSet);
        }catch (Exception e){
            e.printStackTrace();
            return fail("查询失败");
        }
    }


}
